package api

import (
	"blogdemo/gin/errmsg"
	"blogdemo/gin/model"
	"github.com/gin-gonic/gin"
)

func DeleteArticle(c *gin.Context) {
	var art model.Article
	// 绑定数据模型
	_ = c.ShouldBind(&art)

	result := model.EraseArticle(art.Author, art.Title)
	if result == errmsg.ARTICLE_INEXIST {
		c.JSON(400, gin.H{
			"status": errmsg.ARTICLE_INEXIST,
			"data":   art,
			"msg":    errmsg.GetErrMsg(errmsg.ARTICLE_INEXIST),
		})
	} else {
		c.JSON(200, gin.H{
			"status": errmsg.SUCCESS,
			"data":   art,
			"msg":    errmsg.GetErrMsg(errmsg.SUCCESS),
		})
	}
}
